﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;

namespace DARE
{
    /// <summary>
    /// Represents a widget that only shows an image
    /// </summary>
    [AttrTypeDependentSerializable(typeof(CStaticImageData))]
    public class CStaticImage : CWidget
    {
        #region fields
        
        public CHudTexture Image { get { return m_texture; } set { m_texture = value; } }
        public bool ConserveAspectRation { get; set; }

        #endregion

        #region ctor

        public CStaticImage(CHUDSystem hud, CWidget parent, string name)
            : base(hud, parent, name)
        {
            Image = new CHudTexture();
            ConserveAspectRation = true;

            Size = new Vector2(64, 64);
        }

        public override bool Draw(GameTime gameTime)
        {
            Rectangle r = m_rect;
            if (ConserveAspectRation)
            {
                int width;
                int height;
                if (m_rect.Width - Image.Body.Width < m_rect.Height - Image.Body.Height)
                {
                    width = m_rect.Width;
                    height = Image.Body.Height * width / Image.Body.Width;
                }
                else
                {
                    width = Image.Body.Width * m_rect.Height / Image.Body.Height;
                    height = m_rect.Height;
                }
                m_rect.X = (int)(m_rect.X + ((m_rect.Width / 2.0f) - (width / 2.0f)));
                m_rect.Y = (int)(m_rect.Y + ((m_rect.Height / 2.0f) - (height / 2.0f)));
                m_rect.Width = width;
                m_rect.Height = height;
            }
            base.Draw(gameTime);
            m_rect = r;
            return true;
        }

        #endregion
    }
}
